/**
 * 简洁版地图预览组件
 * 优化样式，避免开发工具API限制
 */

Component({
  properties: {
    latitude: {
      type: Number,
      value: 23.129163
    },
    longitude: {
      type: Number,
      value: 113.264435
    },
    address: {
      type: String,
      value: ''
    },
    addressName: {
      type: String,
      value: '商家位置'
    },
    scale: {
      type: Number,
      value: 16
    }
  },

  data: {
    markers: [] as any[]
  },

  lifetimes: {
    attached() {
      this.updateMarkers();
    }
  },

  observers: {
    'latitude, longitude': function() {
      this.updateMarkers();
    }
  },

  methods: {
    /**
     * 更新地图标记
     */
    updateMarkers() {
      const { latitude, longitude, addressName } = this.properties;
      
      if (!latitude || !longitude) {
        return;
      }

      this.setData({
        markers: [{
          id: 1,
          latitude,
          longitude,
          width: 30,
          height: 30,
          anchor: {
            x: 0.5,
            y: 1
          }
        }]
      });
    },

    /**
     * 在微信地图中打开
     */
    openInMap() {
      const { latitude, longitude, address, addressName } = this.properties;
      
      wx.openLocation({
        latitude,
        longitude,
        name: addressName,
        address: address,
        scale: 16
      });
    },

    /**
     * 导航到该位置
     */
    navigate() {
      this.openInMap();
    }
  }
});


